
import "./draw.css"
import React from 'react'
import { Button, Select, Space, DatePicker, message } from 'antd'
import UpdateAll from "../../../component/promotion/updateAll";
import { inject, observer } from "mobx-react";



const { Option } = Select;

const { RangePicker } = DatePicker;
@inject('xingYunChouJiang')
@observer

class UpdateDraw extends React.Component {

    componentWillMount() {
        this.props.xingYunChouJiang.selGoods()
    }

    bangDing = (name) => {
        return (e) => this.props.xingYunChouJiang.insertStart(name, e)
    }


    render() {
        let { myFrom, goodslist } = this.props.xingYunChouJiang

        let methodInsert = () => {
            if (myFrom.goodsId && myFrom.groudNum && myFrom.ludrPrice && myFrom.ludrNum && myFrom.ludrRule && myFrom.ludrDate) {
                this.props.xingYunChouJiang.insertTab().then(data => {
                    data === 200 ? this.props.history.push('/Home/cuXiao/Draw/xingYunChouJiang') : message.error('添加失败')
                })
            } else {
                message.warning('请先完善数据')


            }

        }

        let temp

        if (myFrom.inUpdate) {
            temp = <div className="itemContentRow">
                <span>商品名称：</span>
                <span>{myFrom.goodsName}</span>
            </div>
        }else{
            temp = <div>

                <div className="itemContentRow">
                    <span>商品关键字:</span>
                    <input type="text" value={myFrom.keyWord} onChange={this.bangDing('keyWord')} placeholder="此劵可抵的金额" />
                    <Button type="primary">搜索</Button>
                </div>

                <div className="itemContentRow">
                    <span>商品名称:</span>
                    <Select placeholder="请选择商品" defaultValue={goodslist.goodsName} style={{ width: 200 }} onChange={this.bangDing('goodsId')}>
                        {goodslist.map(item => {
                            return <Option key={item.goodsId} value={item.goodsId}>{item.goodsName}</Option>
                        })}
                    </Select>
                    {/* <input type="text" value={myFrom.goodsName} onChange={bangDing('goodsName')} placeholder="此劵可抵的金额" />  */}
                </div>
            </div>
        }
        return (
            <div className="draw">
                <h1>新增抽奖</h1>
                {/* <UpdateAll text='hahahah' value={chouJiangInput.keyword} /> */}

                {temp}

                <div className="itemContentRow">
                    <span>活动日期:</span>
                    <Space direction={myFrom.stateDate} size={12}>
                        <RangePicker onChange={this.bangDing('ludrDate')} size='middle' />
                    </Space>
                </div>

                <div className="itemContentRow">
                    <span>团购人数:</span>
                    <input type="text" value={myFrom.groudNum} onChange={this.bangDing('groudNum')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>抽奖价格:</span>
                    <input type="text" value={myFrom.ludrPrice} onChange={this.bangDing('ludrPrice')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>抽奖人数:</span>
                    <input type="text" value={myFrom.ludrNum} onChange={this.bangDing('ludrNum')} placeholder="此劵可抵的金额" />
                </div>

                <div className="itemContentRow">
                    <span>抽奖规则:</span>
                    <input type="text" value={myFrom.ludrRule} onChange={this.bangDing('ludrRule')} placeholder="此劵可抵的金额" />
                </div>

                <Button type="primary" onClick={methodInsert}>确定</Button>

            </div>
        )
    }
}


export default UpdateDraw